home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2008 February / PCWFEB08.iso / Software / Resources / Developers / XAMPP 1.5.4 / Windows installer / xampp-win32-1.5.4-installer.exe / xampp / php / pear / Net / NNTP.php < prev    next >
Encoding:
PHP Script  |  2005-07-07  |  25.3 KB  |  944 lines

  1. <?php
  2. /* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4 foldmethod=marker: */
  3. // +----------------------------------------------------------------------+
  4. // | PHP Version 4                                                        |
  5. // +----------------------------------------------------------------------+
  6. // | Copyright (c) 1997-2003 The PHP Group                                |
  7. // +----------------------------------------------------------------------+
  8. // | This source file is subject to version 2.0 of the PHP license,       |
  9. // | that is bundled with this package in the file LICENSE, and is        |
  10. // | available at through the world-wide-web at                           |
  11. // | http://www.php.net/license/2_02.txt.                                 |
  12. // | If you did not receive a copy of the PHP license and are unable to   |
  13. // | obtain it through the world-wide-web, please send a note to          |
  14. // | license@php.net so we can mail you a copy immediately.               |
  15. // +----------------------------------------------------------------------+
  16. // | Authors: Martin Kaltoft   <martin@nitro.dk>                          |
  17. // |          Tomas V.V.Cox    <cox@idecnet.com>                          |
  18. // |          Heino H. Gehlsen <heino@gehlsen.dk>                         |
  19. // +----------------------------------------------------------------------+
  20. // $Id: NNTP.php,v 1.30.2.4 2005/01/19 08:39:11 heino Exp $
  21.  
  22. require_once 'Net/NNTP/Protocol/Client.php';
  23.  
  24. // {{{ constants
  25.  
  26. /* NNTP Authentication modes */
  27. define('NET_NNTP_AUTHORIGINAL', 'original');
  28. define('NET_NNTP_AUTHSIMPLE',   'simple');
  29. define('NET_NNTP_AUTHGENERIC',  'generic');
  30.  
  31. // Deprecated due to naming
  32. define('PEAR_NNTP_AUTHORIGINAL', NET_NNTP_AUTHORIGINAL);
  33. define('PEAR_NNTP_AUTHSIMPLE',   NET_NNTP_AUTHSIMPLE);
  34. define('PEAR_NNTP_AUTHGENERIC',  NET_NNTP_AUTHGENERIC);
  35.  
  36. // }}}
  37. // {{{ Net_NNTP
  38.  
  39. /**
  40.  * The Net_NNTP class is an almost 100 % backward compatible 
  41.  * frontend class to the Net_NNTP_Protocol_Client class.
  42.  * 
  43.  * ATTENTION!!!
  44.  * This class should NOT be used in new projects. It is meant
  45.  * as a drop in replacement to the outdated v0.2, and uses 
  46.  * excatly the same protocol implementation as the new 
  47.  * Net_NNTP_Client class, but has a lot of deprecated 
  48.  * methods etc.
  49.  *
  50.  * @category   Net
  51.  * @package    Net_NNTP
  52.  * @author     Martin Kaltoft   <martin@nitro.dk>
  53.  * @author     Tomas V.V.Cox    <cox@idecnet.com>
  54.  * @author     Heino H. Gehlsen <heino@gehlsen.dk>
  55.  * @version    $Id: NNTP.php,v 1.30.2.4 2005/01/19 08:39:11 heino Exp $
  56.  * @access     public
  57.  * @see        Net_NNTP_Client
  58.  * @since      Class available since Release 0.1.0
  59.  * @deprecated Class deprecated in Release 0.10.0
  60.  */
  61. class Net_NNTP extends Net_NNTP_Protocol_Client
  62. {
  63.     // {{{ properties
  64.  
  65.     /**
  66.      * File pointer of the nntp-connection
  67.      *
  68.      * @var 
  69.      * @access public
  70.      */
  71.     var $fp = null;
  72.  
  73.     /**
  74.      * @var int
  75.      * @access public
  76.      * @deprecated use last() instead
  77.      */
  78.     var $max;
  79.  
  80.     /**
  81.      * @var int
  82.      * @access public
  83.      * @deprecated use last() instead
  84.      */
  85.     var $min;
  86.  
  87.     /**
  88.      * Used for storing information about the currently selected group
  89.      *
  90.      * @var array
  91.      * @access private
  92.      * @since 0.3
  93.      */
  94.     var $_currentGroup = null;
  95.  
  96.     // }}}
  97.     // {{{ constructor
  98.  
  99.     /**
  100.      * Constructor
  101.      */
  102.     function Net_NNTP()
  103.     {
  104.         parent::Net_NNTP_Protocol_Client();
  105.     }
  106.  
  107.     // }}}
  108.     // {{{ connect()
  109.  
  110.     /**
  111.      * Connect to the newsserver.
  112.      *
  113.      * The function currently allows automatic authentication via the three last parameters, 
  114.      * but this feature is to be considered depresated (use connectAuthenticated instead)
  115.      *
  116.      * In the future, this function will just be inherrited from the parent,
  117.      * and thus the last three parameters will no longer be used to authenticate.
  118.      *
  119.      * @param optional string $host The adress of the NNTP-server to connect to.
  120.      * @param optional int $port The port to connect to.
  121.      * @param optional string $user Deprecated!
  122.      * @param optional string $pass Deprecated!
  123.      * @param optional string $authmode Deprecated!
  124.      *
  125.      * @return mixed (bool) true on success or (object) pear_error on failure
  126.      * @access public
  127.      * @see Net_NNTP::quit()
  128.      * @see Net_NNTP::connectAuthenticated()
  129.      * @see Net_NNTP::authenticate()
  130.      */
  131.     function connect($host = NET_NNTP_PROTOCOL_CLIENT_DEFAULT_HOST,
  132.                      $port = NET_NNTP_PROTOCOL_CLIENT_DEFAULT_PORT,
  133.                      $user = null,
  134.                      $pass = null,
  135.                      $authmode = NET_NNTP_AUTHORIGINAL)
  136.     {
  137.         // Currently this function just 'forwards' to connectAuthenticated().
  138.         $R = $this->connectAuthenticated($user, $pass, $host, $port, $authmode);
  139.  
  140.         if (PEAR::isError($R)) {
  141.             return $R;
  142.         }
  143.  
  144.         $this->fp = $this->_socket->fp;
  145.  
  146.         return $R;
  147.     }
  148.  
  149.  
  150.     // }}}
  151.     // {{{ connectAuthenticated()
  152.  
  153.     /**
  154.      * Connect to the newsserver, and authenticate. If no user/pass is specified, just connect.
  155.      *
  156.      * @param optional string $user The user name to authenticate with
  157.      * @param optional string $pass The password
  158.      * @param optional string $host The adress of the NNTP-server to connect to.
  159.      * @param optional int $port The port to connect to.
  160.      * @param optional string $authmode The authentication mode
  161.      *
  162.      * @return mixed (bool) true on success or (object) pear_error on failure
  163.      * @access public
  164.      * @since 0.3
  165.      * @see Net_NNTP::connect()
  166.      * @see Net_NNTP::authenticate()
  167.      * @see Net_NNTP::quit()
  168.      * @deprecated use connect() and authenticate() instead
  169.      */
  170.     function connectAuthenticated($user = null,
  171.                                   $pass = null,
  172.                                   $host = NET_NNTP_PROTOCOL_CLIENT_DEFAULT_HOST,
  173.                                   $port = NET_NNTP_PROTOCOL_CLIENT_DEFAULT_PORT,
  174.                                   $authmode = NET_NNTP_AUTHORIGINAL)
  175.     {
  176.         // Until connect() is changed, connect() is called directly from the parent...
  177.         $R = parent::connect($host, $port);
  178.         if (PEAR::isError($R)) {
  179.             return $R;
  180.         }
  181.  
  182.         // Authenticate if username is given
  183.         if ($user != null) {
  184.             $R = $this->authenticate($user, $pass, $authmode);
  185.             if (PEAR::isError($R)) {
  186.                 return $R;
  187.             }
  188.         }
  189.  
  190.         return true;
  191.     }
  192.  
  193.     // }}}
  194.     // {{{ quit()
  195.  
  196.     /**
  197.      * Close connection to the newsserver
  198.      *
  199.      * @access public
  200.      * @see Net_NNTP::connect()
  201.      */
  202.     function quit()
  203.     {
  204.         return $this->cmdQuit();
  205.     }
  206.  
  207.     // }}}
  208.     // {{{ prepareConnection()
  209.  
  210.     /**
  211.      * Connect to the newsserver, and issue a GROUP command
  212.      * Once connection is prepared, we can only fetch articles from one group
  213.      * at a time, to fetch from another group, a new connection has to be made.
  214.      *
  215.      * This is to avoid the GROUP command for every article, as it is very
  216.      * ressource intensive on the newsserver especially when used for
  217.      * groups with many articles.
  218.      *
  219.      * @param string $host The adress of the NNTP-server to connect to.
  220.      * @param optional int $port the port-number to connect to, defaults to 119.
  221.      * @param string $newsgroup The name of the newsgroup to use.
  222.      * @param optional string $user The user name to authenticate with
  223.      * @param optional string $pass The password
  224.      * @param optional string $authmode The authentication mode
  225.      *
  226.      * @return mixed (bool) true on success or (object) pear_error on failure
  227.      * @access public
  228.      *
  229.      * @deprecated Use connect() or connectAuthenticated() instead
  230.      */
  231.     function prepareConnection($host,
  232.                                 $port = 119,
  233.                                 $newsgroup,
  234.                                 $user = null,
  235.                                 $pass = null,
  236.                                 $authmode = NET_NNTP_AUTHORIGINAL)
  237.     {
  238.         /* connect to the server */
  239.         $R = $this->connect($host, $port, $user, $pass, $authmode);
  240.         if (PEAR::isError($R)) {
  241.             return $R;
  242.         }
  243.  
  244.         /* issue a GROUP command */
  245.         $R = $this->selectGroup($newsgroup);
  246.         if (PEAR::isError($R)) {
  247.             return $R;
  248.         }
  249.  
  250.         return true;
  251.     }
  252.  
  253.     function prepare_connection($nntpserver,
  254.                                 $port = 119,
  255.                                 $newsgroup,
  256.                                 $user = null,
  257.                                 $pass = null,
  258.                                 $authmode = NET_NNTP_AUTHORIGINAL)
  259.     {
  260.         return $this->prepareConnection($nntpserver, $port, $newsgroup, $user, $pass, $authmode);
  261.     }
  262.                                                                                     
  263.     // }}}
  264.     // {{{ authenticate()
  265.  
  266.     /**
  267.      * Auth process (not yet standarized but used any way)
  268.      * http://www.mibsoftware.com/userkt/nntpext/index.html
  269.      *
  270.      * @param string $user The user name
  271.      * @param optional string $pass The password if needed
  272.      * @param optional string $mode Authinfo type: original, simple, generic
  273.      *
  274.      * @return mixed (bool) true on success or (object) pear_error on failure
  275.      * @access public
  276.      * @since 0.3
  277.      * @see Net_NNTP::connect()
  278.      */
  279.     function authenticate($user, $pass, $mode = NET_NNTP_AUTHORIGINAL)
  280.     {
  281.         // Username is a must...
  282.         if ($user == null) {
  283.             return PEAR::throwError('No username supplied', null);
  284.         }
  285.  
  286.         // Use selected authentication method
  287.         switch ($mode) {
  288.             case NET_NNTP_AUTHORIGINAL:
  289.                 return $this->cmdAuthinfo($user, $pass);
  290.                 break;
  291.             case NET_NNTP_AUTHSIMPLE:
  292.                 return $this->cmdAuthinfoSimple($user, $pass);
  293.                 break;
  294.             case NET_NNTP_AUTHGENERIC:
  295.                 return $this->cmdAuthinfoGeneric($user, $pass);
  296.                 break;
  297.             default:
  298.                 return PEAR::throwError("The auth mode: '$mode' is unknown", null);
  299.         }
  300.     }
  301.  
  302.     // }}}
  303.     // {{{ isConnected()
  304.  
  305.     /**
  306.      * Test whether we are connected or not.
  307.      *
  308.      * @return bool true or false
  309.      * @access public
  310.      * @see Net_NNTP::connect()
  311.      * @see Net_NNTP::quit()
  312.      */
  313.     function isConnected()
  314.     {
  315.         return parent::isConnected();
  316.     }
  317.     
  318.     function is_connected()
  319.     {
  320.     return $this->isConnected();
  321.     }
  322.  
  323.     // }}}
  324.     // {{{ selectGroup()
  325.  
  326.     /**
  327.      * Selects a news group (issue a GROUP command to the server)
  328.      *
  329.      * @param string $newsgroup The newsgroup name
  330.      *
  331.      * @return mixed (array) Groups info on success or (object) pear_error on failure
  332.      * @access public
  333.      * @see group()
  334.      * @see count()
  335.      * @see first()
  336.      * @see last()
  337.      */
  338.     function selectGroup($newsgroup)
  339.     {
  340.         $response_arr = $this->cmdGroup($newsgroup);
  341.         if (PEAR::isError($response_arr)) {
  342.             return $response_arr;
  343.         }
  344.  
  345.         $this->_currentGroup = $response_arr;
  346.  
  347.         // Deprecated / historical                      
  348.         $response_arr['min'] =& $response_arr['first'];
  349.         $response_arr['max'] =& $response_arr['last'];
  350.         $this->min =& $response_arr['min'];
  351.         $this->max =& $response_arr['max'];
  352.  
  353.         return $response_arr;
  354.     }
  355.  
  356.     function select_group($newsgroup)
  357.     {
  358.         return $this->selectGroup($newsgroup);
  359.     }
  360.  
  361.     // }}}
  362.     // {{{ getGroups()
  363.  
  364.     /**
  365.      * Fetches a list of all avaible newsgroups
  366.      *
  367.      * @return mixed (array) nested array with informations about existing newsgroups on success or (object) pear_error on failure
  368.      * @access public
  369.      */
  370.     function getGroups()
  371.     {
  372.         // Get groups
  373.         $groups = $this->cmdList();
  374.         if (PEAR::isError($groups)) {
  375.             return $groups;
  376.         }
  377.  
  378.         // Deprecated / historical
  379.         foreach (array_keys($groups) as $k) {
  380.             $groups[$k]['posting_allowed'] =& $groups[$k]['posting'];
  381.         }
  382.  
  383.         // Get group descriptions
  384.         $descriptions = $this->cmdListNewsgroups();
  385.         if (PEAR::isError($descriptions)) {
  386.             return $descriptions;
  387.         }
  388.     
  389.         // Set known descriptions for groups
  390.         if (count($descriptions) > 0) {
  391.             foreach ($descriptions as $k=>$v) {
  392.                 $groups[$k]['desc'] = $v;
  393.             }
  394.         }
  395.  
  396.         return $groups;
  397.     }
  398.  
  399.     function get_groups()
  400.     {
  401.     return $this->getGroups();
  402.     }
  403.  
  404.     // }}}
  405.     // {{{ getOverview()
  406.  
  407.     /**
  408.      * Fetch message header from message number $first to $last
  409.      *
  410.      * The format of the returned array is:
  411.      * $messages[message_id][header_name]
  412.      *
  413.      * @param integer $first first article to fetch
  414.      * @param integer $last  last article to fetch
  415.      *
  416.      * @return mixed (array) nested array of message and there headers on success or (object) pear_error on failure
  417.      * @access public
  418.      * @see Net_NNTP::getOverviewFormat()
  419.      * @see Net_NNTP::getReferencesOverview()
  420.      */
  421.     function getOverview($first, $last)
  422.     {
  423.         $overview = $this->cmdXOver($first.'-'.$last);
  424.         if (PEAR::isError($overview)) {
  425.             return $overview;
  426.         }
  427.  
  428.         return $overview;
  429.     }
  430.  
  431.     function get_overview($first, $last)
  432.     {
  433.         $this->getOverview($first, $last);
  434.     }
  435.  
  436.     // }}}
  437.     // {{{ getOverviewFormat()
  438.  
  439.     /**
  440.      * Returns a list of avaible headers which are send from newsserver to client for every news message
  441.      *
  442.      * @return mixed (array) header names on success or (object) pear_error on failure
  443.      * @access public
  444.      * @see Net_NNTP::getOverview()
  445.      */
  446.     function getOverviewFormat()
  447.     {
  448.         return $this->cmdListOverviewFMT();
  449.     }
  450.  
  451.     // }}}
  452.     // {{{ getOverviewFmt()
  453.  
  454.     /**
  455.      * Returns a list of avaible headers which are send from newsserver to client for every news message
  456.      *
  457.      * @return mixed (array) header names on success or (object) pear_error on failure
  458.      * @access public
  459.      * @deprecated use getOverviewFormat() instead
  460.      */
  461.     function getOverviewFmt()
  462.     {
  463.         return $this->getOverviewFormat();
  464.     }
  465.  
  466.     function get_overview_fmt()
  467.     {
  468.         $this->getOverviewFmt();
  469.     }
  470.     
  471.     // }}}
  472.     // {{{ getReferencesOverview()
  473.  
  474.     /**
  475.      * Fetch a list of each message's reference header.
  476.      *
  477.      * @param integer $first first article to fetch
  478.      * @param integer $last  last article to fetch
  479.      *
  480.      * @return mixed (array) nested array of references on success or (object) pear_error on failure
  481.      *
  482.      * @return mixed (array) nested array of message and there headers on success or (object) pear_error on failure
  483.      * @access public
  484.      * @see Net_NNTP::getOverview()
  485.      */
  486.     function getReferencesOverview($first, $last)
  487.     {
  488.         $overview = $this->cmdXROver($first.'-'.$last);
  489.         if (PEAR::isError($overview)) {
  490.             return $overview;
  491.         }
  492.     
  493.         return $overview;
  494.     }
  495.  
  496.     // }}}
  497.     // {{{ post()
  498.  
  499.     /**
  500.      * Post an article to a number of newsgroups.
  501.      *
  502.      * (Among the aditional headers you might think of adding could be:
  503.      * "NNTP-Posting-Host: <ip-of-author>", which should contain the IP-adress
  504.      * of the author of the post, so the message can be traced back to him.
  505.      * Or "Organization: <org>" which contain the name of the organization
  506.      * the post originates from)
  507.      *
  508.      * @param string $subject The subject of the post.
  509.      * @param string $newsgroup The newsgroup to post to.
  510.      * @param string $from Name + email-adress of sender.
  511.      * @param string $body The body of the post itself.
  512.      * @param optional string $aditional Aditional headers to send.
  513.      *
  514.      * @return mixed (string) server response on success or (object) pear_error on failure
  515.      * @access public
  516.      */
  517.     function post($subject, $newsgroup, $from, $body, $aditional = '')
  518.     {
  519.         return $this->cmdPost($newsgroup, $subject, $body, $from, $aditional);
  520.     }
  521.  
  522.     // }}}
  523.     // {{{ getArticleRaw()
  524.  
  525.     /**
  526.      * Get an article (raw data)
  527.      *
  528.      * @param mixed $article Either the message-id or the message-number on the server of the article to fetch.
  529.      * @param bool  $implode When true the result array is imploded to a string, defaults to true.
  530.      *
  531.      * @return mixed (array/string) The headers on success or (object) pear_error on failure
  532.      * @access public
  533.      * @since 0.3
  534.      * @see getHeaderRaw()
  535.      * @see getBodyRaw()
  536.      */
  537.     function getArticleRaw($article, $implode = true)
  538.     {
  539.         $data = $this->cmdArticle($article);
  540.         if (PEAR::isError($data)) {
  541.             return $data;
  542.         }
  543.         if ($implode == true) {
  544.             $data = implode("\r\n", $data);
  545.         }
  546.         return $data;
  547.     }
  548.  
  549.     // }}}
  550.     // {{{ getArticle()
  551.  
  552.     /**
  553.      * Get an article (deprecated)
  554.      *
  555.      * @param mixed $article Either the message-id or the message-number on the server of the article to fetch.
  556.      *
  557.      * @return mixed (string) The headers on success or (object) pear_error on failure
  558.      * @access public
  559.      * @deprecated Use getArticleRaw() instead
  560.      */
  561.     function getArticle($article)
  562.     {
  563.         return $this->getArticleRaw($article);
  564.     }
  565.  
  566.     function get_article($article)
  567.     {
  568.         return $this->getArticle($article);
  569.     }
  570.  
  571.     // }}}
  572.     // {{{ getHeaderRaw()
  573.  
  574.     /**
  575.      * Get the headers of an article (raw data)
  576.      *
  577.      * @param mixed $article Either the (string) message-id or the (int) message-number on the server of the article to fetch.
  578.      * @param bool  $implode When true the result array is imploded to a string, defaults to true.
  579.      *
  580.      * @return mixed (array/string) headers on success or (object) pear_error on failure
  581.      * @access public
  582.      * @since 0.3
  583.      * @see getArticleRaw()
  584.      * @see getBodyRaw()
  585.      */
  586.     function getHeaderRaw($article, $implode = true)
  587.     {
  588.         $data = $this->cmdHead($article);
  589.         if (PEAR::isError($data)) {
  590.             return $data;
  591.         }
  592.         if ($implode == true) {
  593.             $data = implode("\r\n", $data);
  594.         }
  595.         return $data;
  596.     }
  597.  
  598.     // }}}
  599.     // {{{ getHeaders()
  600.  
  601.     /**
  602.      * Get the headers of an article (deprecated)
  603.      *
  604.      * @param mixed $article Either the (string) message-id or the (int) message-number on the server of the article to fetch.
  605.      *
  606.      * @return mixed (string) headers on success or (object) pear_error on failure
  607.      * @access public
  608.      * @deprecated Use getHeaderRaw() instead
  609.      */
  610.     function getHeaders($article)
  611.     {
  612.         return $this->getHeaderRaw($article);
  613.     }
  614.  
  615.     function get_headers($article)
  616.     {
  617.         return $this->getHeaders($article);
  618.     }
  619.  
  620.     // }}}
  621.     // {{{ getBodyRaw()
  622.  
  623.     /**
  624.      * Get the body of an article (raw data)
  625.      *
  626.      * @param mixed $article Either the message-id or the message-number on the server of the article to fetch.
  627.      * @param bool  $implode When true the result array is imploded to a string, defaults to true.
  628.      *
  629.      * @return mixed (array/string) headers on success or (object) pear_error on failure
  630.      * @access public
  631.      * @since 0.3
  632.      * @see getHeaderRaw()
  633.      * @see getArticleRaw()
  634.      */
  635.     function getBodyRaw($article, $implode = true)
  636.     {
  637.         $data = $this->cmdBody($article);
  638.         if (PEAR::isError($data)) {
  639.             return $data;
  640.         }
  641.         if ($implode == true) {
  642.             $data = implode("\r\n", $data);
  643.         }
  644.         return $data;
  645.     }
  646.  
  647.     // }}}
  648.     // {{{ getBody()
  649.  
  650.     /**
  651.      * Get the body of an article (deprecated)
  652.      *
  653.      * @param mixed $article Either the message-id or the message-number on the server of the article to fetch.
  654.      *
  655.      * @return mixed (string) headers on success or (object) pear_error on failure
  656.      * @access public
  657.      * @deprecated Use getBodyRaw() instead
  658.      */
  659.     function getBody($article)
  660.     {
  661.         return $this->getBodyRaw($article);
  662.     }
  663.  
  664.     function get_body($article)
  665.     {
  666.         return $this->getBody($article);
  667.     }
  668.  
  669.     // }}}
  670.     // {{{ getDate()
  671.  
  672.     /**
  673.      * Get the NNTP-server's internal date
  674.      *
  675.      * Get the date from the newsserver format of returned date:
  676.      *
  677.      * @param optional int $format
  678.      *  - 0: $date - timestamp
  679.      *  - 1: $date['y'] - year
  680.      *       $date['m'] - month
  681.      *       $date['d'] - day
  682.      *
  683.      * @return mixed (mixed) date on success or (object) pear_error on failure
  684.      * @access public
  685.      * @since 0.3
  686.      */
  687.     function getDate($format = 1)
  688.     {
  689.         $date = $this->cmdDate();
  690.         if (PEAR::isError($date)) {
  691.             return $date;
  692.         }
  693.  
  694.         switch ($format) {
  695.             case 1:
  696.                 return array('y' => substr($date, 0, 4), 'm' => substr($date, 4, 2), 'd' => substr($date, 6, 2));
  697.                 break;
  698.  
  699.             case 0:
  700.             default:
  701.                 return $date;
  702.                 break;
  703.         }
  704.     }
  705.  
  706.     // }}}
  707.     // {{{ date()
  708.  
  709.     /**
  710.      * @return mixed (array) date on success or (object) pear_error on failure
  711.      * @access public
  712.      *
  713.      * @deprecated Use getDate() instead
  714.      */
  715.     function date()
  716.     {
  717.         return $this->getDate();
  718.     }
  719.  
  720.     // }}}
  721.     // {{{ count()
  722.  
  723.     /**
  724.      * Number of articles in currently selected group
  725.      *
  726.      * @return integer count
  727.      * @access public
  728.      * @since 0.3
  729.      * @see Net_NNTP::selectGroup()
  730.      * @see Net_NNTP::group()
  731.      * @see Net_NNTP::first()
  732.      * @see Net_NNTP::last()
  733.      */
  734.     function count()
  735.     {
  736.         return $this->_currentGroup['count'];
  737.     }
  738.  
  739.     // }}}
  740.     // {{{ last()
  741.  
  742.     /**
  743.      * Maximum article number in current group
  744.      *
  745.      * @return integer maximum
  746.      * @access public
  747.      * @since 0.3
  748.      * @see Net_NNTP::selectGroup()
  749.      * @see Net_NNTP::group()
  750.      * @see Net_NNTP::first()
  751.      * @see Net_NNTP::count()
  752.      */
  753.     function last()
  754.     {
  755.         return $this->_currentGroup['last'];
  756.     }
  757.  
  758.     // }}}
  759.     // {{{ max()
  760.  
  761.     /**
  762.      * @return integer maximum
  763.      * @access public
  764.      *
  765.      * @deprecated Use last() instead
  766.      */
  767.     function max()
  768.     {
  769.         return $this->last();
  770.     }
  771.  
  772.     // }}}
  773.     // {{{ first()
  774.  
  775.     /**
  776.      * Minimum article number in current group
  777.      *
  778.      * @return integer minimum
  779.      * @access public
  780.      * @since 0.3
  781.      * @see Net_NNTP::selectGroup()
  782.      * @see Net_NNTP::group()
  783.      * @see Net_NNTP::last()
  784.      * @see Net_NNTP::count()
  785.      */
  786.     function first()
  787.     {
  788.         return $this->_currentGroup['first'];
  789.     }
  790.  
  791.     // }}}
  792.     // {{{ min()
  793.  
  794.     /**
  795.      * @return integer minimum
  796.      * @access public
  797.      *
  798.      * @deprecated Use first() instead
  799.      */
  800.     function min()
  801.     {
  802.         return $this->first();
  803.     }
  804.  
  805.     // }}}
  806.     // {{{ group()
  807.  
  808.     /**
  809.      * Currently selected group
  810.      *
  811.      * @return string group
  812.      * @access public
  813.      * @since 0.3
  814.      * @see Net_NNTP::selectGroup()
  815.      * @see Net_NNTP::first()
  816.      * @see Net_NNTP::last()
  817.      * @see Net_NNTP::count()
  818.      */
  819.     function group()
  820.     {
  821.         return $this->_currentGroup['group'];
  822.     }
  823.  
  824.     // }}}
  825.     // {{{ splitHeaders()
  826.  
  827.     /**
  828.      * Get the headers of an article from the currently open connection, and parse them into a keyed array.
  829.      *
  830.      * @param mixed $article Either the (string) message-id or the (int) message-number on the server of the article to fetch.
  831.      *
  832.      * @return mixed (array) Assoc array with headers names as key on success or (object) pear_error on failure
  833.      * @access public
  834.      */
  835.     function splitHeaders($article)
  836.     {
  837.         // Retrieve headers
  838.         $headers = $this->getHeaderRaw($article, false);
  839.         if (PEAR::isError($headers)) {
  840.             return PEAR::throwError($headers);
  841.         }
  842.     
  843.         $return = array();
  844.  
  845.         // Loop through all header field lines
  846.         foreach ($headers as $field) {
  847.             // Separate header name and value
  848.             if (!preg_match('/([\S]+)\:\s*(.*)\s*/', $field, $matches)) {
  849.                 // Fail...
  850.             }
  851.             $name = $matches[1];
  852.             $value = $matches[2];
  853.             unset($matches);
  854.  
  855.             // Add header to $return array
  856.             if (isset($return[$name]) AND is_array($return[$name])) {
  857.                 // The header name has already been used at least two times.
  858.                 $return[$name][] = $value;
  859.             } elseif (isset($return[$name])) {
  860.                 // The header name has already been used one time -> change to nedted values.
  861.                 $return[$name] = array($return[$name], $value);
  862.             } else {
  863.                 // The header name has not used until now.
  864.             $return[$name] = $value;
  865.             }
  866.         }
  867.  
  868.         return $return;
  869.     }
  870.  
  871.     function split_headers($article)
  872.     {
  873.         return $this->splitHeaders($article);
  874.     }
  875.     
  876.     // }}}
  877.     // {{{ responseCode()
  878.  
  879.     /**
  880.      * returns the response code of a newsserver command
  881.      *
  882.      * @param string $response newsserver answer
  883.      *
  884.      * @return integer response code
  885.      * @access public
  886.      *
  887.      * @deprecated
  888.      */
  889.     function responseCode($response)
  890.     {
  891.         $parts = explode(' ', ltrim($response), 2);
  892.         return (int) $parts[0];
  893.     }
  894.  
  895.     // }}}
  896.     // {{{ _getData()
  897.  
  898.     /**
  899.      * Get data until a line with only a '.' in it is read and return data.
  900.      *
  901.      * @return mixed (string) data on success or (object) pear_error on failure
  902.      * @access private
  903.      *
  904.      * @deprecated Use _getTextResponse() instead
  905.      */
  906.     function _getData()
  907.     {
  908.         return $this->_getTextResponse();
  909.     }
  910.  
  911.     function get_data()
  912.     {
  913.     return $this->_getData();
  914.     }
  915.  
  916.     // }}}
  917.     // {{{ command()
  918.  
  919.     /**
  920.      * Issue a command to the NNTP server
  921.      *
  922.      * @param string $cmd The command to launch, ie: "ARTICLE 1004853"
  923.      *
  924.      * @return mixed (int) response code on success or (object) pear_error on failure
  925.      * @access public
  926.      */
  927.     function command($cmd)
  928.     {
  929.         $code = $this->_sendCommand($cmd);
  930.         if (PEAR::isError($code)) {
  931.             return PEAR::throwError($code);
  932.         }
  933.     
  934.         return $code.' '.$this->currentStatusResponse()."\r\n";
  935.     }
  936.  
  937.     // }}}
  938.  
  939. }
  940.  
  941. // }}}
  942.  
  943. ?>
  944.